#include <iostream>
#include <list>
#include <string>

using namespace std;

int main()
{
	list<char> left;
	bool flag = true;
	string input_s;
	cin >> input_s;
	string::iterator iter = input_s.begin();
	while (iter != input_s.end() && flag) {
		switch (*iter)
		{
		case '(':
			left.push_back(*iter);
			break;
		case '[':
			left.push_back(*iter);
			break;
		case '{':
			left.push_back(*iter);
			break;
		case ')':
			if (left.back() != '(') {
				flag = false;
			}
			else {
				left.pop_back();
			}
			break;
		case ']':
			if (left.back() != '[') {
				flag = false;
			}
			else {
				left.pop_back();
			}
			break;
		case '}':
			if (left.back() != '{') {
				flag = false;
			}
			else {
				left.pop_back();
			}
			break;
		}
		++iter;
	}
	if (flag && left.size() > 0) {
		flag = false;
	}
	if (flag) {
		cout << 1;
	}
	else {
		cout << 0;
	}
}
